<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>onclick</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .bord{
            border: 1px dashed #ee2602;
            width: 90%;
            margin: 20px auto;
        }
        .title{
            font-size: 20px;
            font-weight: bold;
            margin: 20px;
        }
        .introduce{
            font-size: 16px;
            margin: 0 0 20px 50px;
        }
        .red{
            color: red;
        }
    </style>
    <script>
        window.onload = function () {
            document.getElementById('a').onclick = function () {
                document.write("点击成功！")
            }
        };
    </script>
</head>
<body>
<div class="bord">
    <div class="title">onclick</div>
    <div class="introduce">
        onclick 事件会在对象被点击时发生。
    </div>
</div>
<div class="bord">
    <div class="title">演示效果</div>
    <button class="introduce" id="a">打印结果</button>
</div>
<div class="bord">
    <div class="title">代码</div>
    <div class="introduce">
        <pre>
                &lt;script&gt;
        window.onload = function () {
            document.getElementById('a').onclick = function () {
               document.write("点击成功！")
            }
        };
                &lt;/script&gt;
        </pre>
    </div>
</div>
</body>
</html>